/**
 * Created by zander on 2017/12/15.
 */
/**
 * Created by zander on 2017/12/6.
 */
function getProject() {
    var a = document.getElementById("Project");
    var b = a.options[a.selectedIndex].value;
    return b;
}

function clearInfo() {
    var patrn1 = /^[0-9]*[1-9][0-9]*$/;
    var patrn = /^[0-9a-zA-Z]/;
    var inputPhone = $('#inputPhone').val();
    var inputId = $('#inputID').val();
    if (inputPhone == ""){
        alert("手机号为空");
        return false;
    }else if (inputId == ""){
        alert("身份证号为空");
        return false;
    }else if (!patrn1.test(inputPhone)){
        alert("手机号只能输入数字");
        return false;
    }else if (!patrn.test(inputId)){
        alert("身份证格式不正确");
        return false;
    }
    document.getElementById('res').innerText = '';
    var localStorage = window.localStorage;
    var project = getProject();
    var phone = document.getElementById('inputPhone').value;
    var identifier = document.getElementById('inputID').value;
    var username = localStorage.getItem('name');
    sure(username,project, phone, identifier);
}
function sure(username,project, phone, identifier) {
    bootbox.confirm({
        size: "small",
        message: "是否确认授信用户所有授信项?",
        callback: function (result) {
            if (result == true) {
                $.ajax({
                    type: "POST",
                    url: "v1/rd/allC2auth",
                    data: {username:username,project: project, phone: phone, identifier: identifier},
                    dataType: "json",
                    beforeSend:function(){
                        $("body").mLoading("show");
                    },
                    success: function (ret) {
                       var massage = projectRet(project,ret);
                       $("body").mLoading("hide");
                       $("#res").append(massage);
                    },
                    error: function() {
                        $("body").mLoading("hide");
                        $("#res").append("Error 500,请联系开发人员！");
                    }
                });
            }
        }
    })
}

function projectRet(project,ret) {
    if (project == "jk"){
        if (ret.status == "0000"){
            var msg = "操作成功！请观察账户授信信息,如有问题请您联系自动化测试";
            return msg
        }else {
            var msg = "操作失败！请联系自动化测试。";
            return msg
        }
    }else if (project == "zed"){
        if (ret.status == "0000"){
            var msg = "操作成功！请观察账户授信信息,如有问题请您联系自动化测试"
            return msg
        }else {
            var msg = "操作失败！请联系自动化测试。";
            return msg
        }
    }else if (project == "sudi"){
        var content = ret.content
        var alertMsg = [];
        for (x = 0; x < content.length; x++) {
            alertMsg.push(ret.content[x]['message']);
            alertMsg.push(content[x]['type']);
        }
        var checkWhiteList = alertMsg[0].match("whiteList");
        if (checkWhiteList == null){
            return alertMsg;
        }else{
            var msg ="用户身份证号不是白名单用户！";
            return msg;
        }
    }else if (project == "in"){
        var content = ret.content
        var alertMsg = [];
        for (x = 0; x < content.length; x++) {
            alertMsg.push(ret.content[x]['message']);
            alertMsg.push(content[x]['type']);
        }
        var checkWhiteList = alertMsg[0].match("whiteList");
        if (checkWhiteList == null){
            return alertMsg;
        }else{
            var msg ="用户身份证号不是白名单用户！";
            return msg;
        }
    }
}